/*年轻人，只管向前看，不要管自暴自弃者的话*/

import 'base/ErrorEntity.dart';
import 'base/NWMethod.dart';
import 'dio_manager.dart';

///create by itz on 2024/1/3 11:23
///desc :
class ApiRepository {
  ApiRepository._();

  final DioManager httpClient = DioManager();

  Future request<T>(String path,
      {withLoading = false,
      loadText = "加载中...",
      NWMethod method = NWMethod.POST,
      Map? params,
      Map<String, String>? header,
      Function(T)? success,
      Function(ErrorEntity)? error}) async {
    return httpClient.requestAccept(path,
        withLoading: withLoading,
        loadText: loadText,
        method: method,
        params: params,
        header: header,
        success: success,
        error: error);
  }

  Future requestList<T>(String path,
      {withLoading = false,
      loadText = "加载中...",
      NWMethod method = NWMethod.POST,
      Map? params,
      required Function(List<T>) success,
      Function(ErrorEntity)? error}) async {
    return httpClient.requestListAccept(path,
        withLoading: withLoading, loadText: loadText, method: method, params: params, success: success, error: error);
  }

  static ApiRepository instance = ApiRepository._();
}
